package com.ccit.area.service.impl;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccit.area.mapper.AreaMapper;
import com.ccit.area.service.AreaService;
import com.ccit.model.Area;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Transactional(rollbackFor = Exception.class)
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements AreaService {

    @Autowired
    private AreaMapper areaMapper;

    @Override
    public boolean updateCurrentNum(String name, Integer num) {
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.eq("name", name);
        Area area = areaMapper.selectOne(wrapper);
        area.setCurrent(num+area.getCurrent());

        area.setCurrent(num);

        Integer result = areaMapper.updateById(area);
        if (result == 1)
            return true;
        else
            return false;

    }
}

